import qrcode
from dependence.my_log import MyLoger
from dependence.my_cmd import cmd_run

class XTCWatch():
    def __init__(self):
        self.log = MyLoger().get_logger(__name__)
        self.name = ''#内部型号
        self.module = ''#型号
        self.bindnum = ''#绑定号
        self.serialnum = ''#设备序列号
        # self.emmc_size = ''
        self.platform = ''#设备平台
        self.voltage = ''
        self.module_qrcode = ''
        self.formal_qrcode = ''
        self.sim_operator = ''

    def get_watch_param(self):
        self.bindnum = cmd_run("adb shell getprop ro.boot.bindnumber").strip()  # 获取型号
        self.module = cmd_run("adb shell getprop ro.product.model").strip()  # 获取型号
        self.name = cmd_run("adb shell getprop ro.product.innermodel").strip()  # 获取内部型号
        self.platform = cmd_run("adb shell getprop ro.board.platform").strip()  # 获取平台
        self.sim_operator = cmd_run("adb shell getprop gsm.operator.alpha").strip()  # 获取运营商


    def make_qrode(self):
        '''
        根据绑定号生成二维码
        :return: 'http://watch.okii.com/d/' + self.bindnum
        '''
        if self.bindnum != '':
            qrcodeimg = qrcode.make('http://watch.okii.com/d/' + self.bindnum)
            self.log.debug("已生成二维码")
            self.module_qrcode = qrcodeimg
            qrcodeimg.save("dependence/绑定二维码.png")
        else:
            self.log.err("绑定号不正确，二维码生成失败")

        # if self.bindnum != '':
        #     qrcodeimg = qrcode.make('http://watch.okii.com/d/' + self.bindnum)
        #     self.log.debug("已生成二维码")
        #     self.module_qrcode = qrcodeimg
        #     qrcodeimg.save("绑定二维码.png")
        # else:
        #     self.module_qrcode = None